package top.mcwebsite.playandroid.business.gongzhonghao.impl.ui

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.paging.LoadState
import androidx.paging.compose.LazyPagingItems
import top.mcwebsite.playandroid.business.articles.api.model.ArticleModel
import top.mcwebsite.playandroid.business.gongzhonghao.impl.vm.GongZhongHaoIntent
import top.mcwebsite.playandroid.common.list.EasyLazyListPageColumn
import top.mcwebsite.playandroid.common.uiWidget.SkeletonPage
import top.mcwebsite.playandroid.common.uiWidget.skeleton

@Composable
fun GongZhongHaoItemContent(
    lazyPagingItems: LazyPagingItems<ArticleModel>,
    sendIntent: (GongZhongHaoIntent) -> Unit
) {
    EasyLazyListPageColumn(
        lazyPagingItems = lazyPagingItems,
        loading = {
            SkeletonPage {
                SkeletonUI()
            }
        },
        loadingMoreError = {},
    ) { _, item ->
        GongZhongHaoArticle(articleModel = item) { article ->
            sendIntent(GongZhongHaoIntent.OnClickArticleItemIntent(article))
        }
    }
}

@Composable
fun GongZhongHaoArticle(
    articleModel: ArticleModel,
    onClick: (ArticleModel) -> Unit,
) {
    Column(
        modifier = Modifier
            .fillMaxWidth()
            .clickable { onClick(articleModel) }
            .padding(vertical = 10.dp, horizontal = 12.dp)
    ) {
        Text(text = articleModel.title, style = MaterialTheme.typography.titleMedium)
        Text(
            text = articleModel.niceDate,
            style = MaterialTheme.typography.labelMedium,
            color = LocalContentColor.current.copy(alpha = 0.7f)
        )
    }
}
